begintownscript;

variables;
short creature_count = 0;
short choice = 0;
short pc_counter = 0;
short lead_char = 0;
short pctalker = 0;

body;

beginstate 0; //INIT_STATE
	set_crime_tolerance(2);

	activate_hidden_group(2);
	
	//Set up groups
		//Archers
		add_char_to_group(18,1);
		add_range_to_group(12,13,1);
		add_range_to_group(6,8,1);
		set_level(1001,14);

		//Soldiers
		add_range_to_group(10,11,2);
		add_char_to_group(15,2);
		add_range_to_group(20,23,2);
		set_level(1002, 16);

		//Blademasters
		add_range_to_group(16,17,3);
		add_char_to_group(9,3);
		set_level(1003, 18);

		//First group of rebels
		add_range_to_group(6,11,4);

		//Campfire group
		add_char_to_group(24,5);
		add_range_to_group(16,18,5);
		add_range_to_group(20,22,5);

		//Sniper & guards
		add_char_to_group(14,6);
		add_char_to_group(15,6);
		add_char_to_group(23,6);
		

	//Names & Levels
	set_name(1001,"Rebel Archer");
	set_name(1002,"Rebel Grunt");
	set_name(1003,"Rebel Swordsman");
	set_name(14,"Rebel Sniper");
	set_name(19,"Joshua");
	set_name(24,"Sorkeli");


	//first entrance dialog
	if(get_flag(6,0) == 0) {
		reset_dialog();
		add_dialog_str(0,"Well, the path through the woods led you here. It's barely a cave... more of a crevice in the cliffs, really. But the footprints do lead right up into it.",0);
		add_dialog_str(1,"The sound of the falls is really loud here. Loud enough that you're worried about someone or something sneaking up on you.",0);
		add_dialog_str(2,"Then again, fact that the ground is littered with the bones of small animals is just a bit more disconcerting to you right now.",0);
		run_dialog(1);
		set_flag(6,0,1);
		}
	
break;


beginstate 1; //EXIT_STATE

break;


beginstate 2; //START_STATE
	pc_counter = 0;
	while(char_ok(pc_counter) == 0) {
		pc_counter = pc_counter + 1;
		}
	lead_char = pc_counter;

	//Dialogue after clearing first rebel group
	if((get_flag(6,5) == 0) && (first_group_member(4) == -1)) {
		message_dialog("Having finally dispatched the guards, you pause to catch your breath. These rebels are a bit tougher than the run-of-the-mill bandits you're so used to.","Regrettably, you weren't very quiet about killing them. You soon hear more voices from further down the passage.");
		set_flag(6,5,1);
	}

	//Dialogue after clearing campfire group
	if((get_flag(6,6) == 0) && (first_group_member(5) == -1)) {
		reset_dialog();
		add_dialog_str(0,"Now that this group of sentries lies face down in the dirt, you don't hear any more voices. In fact, the only sounds you hear are the campfire, some birds in the clearing, and the low rumble of the falls.",0);
		add_dialog_str(1,"While the relative silence is a bit disconcerting, you're more alarmed by the fact that you haven't seen anyone who looks like a leader yet.",0);
		run_dialog(1);
		set_flag(6,6,1);
	}

	//Kill party if the crates are all pushed in
	if(get_flag(6,16) == 7) {

		reset_dialog();
		if(char_ok(25) == 1) {
			add_dialog_str(0,"As the last crate is pushed into the water, you hear a satisfied sigh from where you assume Joshua is standing.",0);
			add_dialog_str(1,"_My friends, I win._",0);
		}
		else {
			add_dialog_str(0,"Though Joshua is dead, he did manage to push the last of the crates into the water. You hope against all hope that something goes wrong with his plan.",0);
			add_dialog_str(1,"You listen anxiously for a few moments, and then...",0);
		}
		add_dialog_str(2,"The last thing you hear is the rock around you shattering.",0);
		run_dialog(1);
		
		play_sound(-108);
		pause(2);
		play_sound(-108);
		pause(2);
		play_sound(-108);
		pause(2);
		play_sound(-108);
		pause(2);
		play_sound(-108);
		pause(2);
		play_sound(-108);
		pause(2);
		kill_char(1000,2,0);
	}

break;


beginstate 10; //Nearing the dead spider

	if(get_flag(6,1) == 0) {
		message_dialog("This is a bit unsettling. You see immense spider webs off to the northeast, and something in that direction smells awful.","Hopefully it has nothing to do with the rebels.");
		set_flag(6,1,1);
	}

break;

beginstate 11; //Enter the former lair

	if(get_flag(6,1) == 1) {
		reset_dialog();
		add_dialog_str(0,"It smells even worse in this corner of the cave, and you soon see why. There's an immense, nasty-looking spider at the back of this chamber.",0);
		add_dialog_str(1,"After a tense, quiet moment, you realize that it's not going to attack you, because it's dead. That's probably why it smells so bad, come to think of it. And it also explains the bones.",0);
		run_dialog(1);
		set_flag(6,1,2);
	}

break;

beginstate 12; //Poking the spider's body (specobj)

	if(get_flag(6,1) <= 2) {
		message_dialog("You take a look at the spider's body, and see that it was rather clearly run through with an impressive sword. And unsurprisingly, it smells downright putrid.","Unfortunately, there are no valuables on the spider's body, so you back away.");
		set_flag(6,1,3);
	}
	else if(get_flag(6,1) == 3) {
		message_dialog("The spider corpse is still here, and it still smells horrible. There's really not much you can do with it.","");
	}
break;

beginstate 15; //Nearing the crack in the wall (only triggers for luck/NL)

	if(get_flag(6,2) == 0) {
		//only works with 4 Nature Lore or 5 Luck in ONE PC
		if((get_highest_skill(16) >= 4) || (get_highest_skill(18) >= 5)) {
		print_str_color("You notice an odd-looking crack in the west wall.",4);
		}
	}

break;

beginstate 16; //Secret door

	if(get_flag(6,2) == 0) {
		reset_dialog();
		add_dialog_str(0,"There's definitely something odd about this wall. So, being the adventurers that you are, you decide to poke at it.",0);
		add_dialog_str(1,"You barely tap on the wall, and a crack opens up, prompting you to step through it. On the other side, you find a rough-hewn tunnel that looks like it was made recently.",0);
		add_dialog_str(2,"This must be the way to the rebels.",0);
		run_dialog(1);
		set_flag(6,2,1);
	}

break;


beginstate 20; //first sight of rebel
	
	if(get_flag(6,3) == 0) {
		reset_dialog();
		add_dialog_str(0,"You pause at the bottom of this slope, certain that you heard a voice up ahead. Silently crouching in the shadows, you hear a voice through the sound of the falls.",0);
		add_dialog_str(1,"_...damn Empire rats. If they find us, we're done for._",8);
		add_dialog_str(2,"Another voice follows the first.",0);
		add_dialog_str(3,"_They might find us, but they won't get past us. Be ready._",8);
		add_dialog_str(4,"The voices sink beneath the dull roar of the falls. But whoever they are, it seems that they know you're here.",0);
		run_dialog(1);
		set_flag(6,3,1);
	}

break;

beginstate 21; //looking out the cliff windows

	if(get_flag(6,4) == 0) {
		reset_dialog();
		add_dialog_str(0,"This window is surprisingly small, but probably adequate for the rebel archers' uses. You probably never would have seen it from the outside.",0);
		add_dialog_str(1,"You're suddenly very glad that Private Scott didn't recommend taking a boat to get here. You wouldn't have lasted a minute with invisible archers picking you off.",0);
		run_dialog(1);
		set_flag(6,4,1);
	}

break;

beginstate 22; //looking at the low-light braziers (specobj)
	message_dialog("Whoever designed this brazier took great care to minimize the light it produced. This probably helps the rebels avoid detection.","Regrettably, there's nothing you can really do with it.");
break;


beginstate 23; //ridiculous amount of supplies (specobj)

	if(get_flag(6,18) == 0) {
		reset_dialog();
		add_dialog_str(0,"This is a ridiculous amount of supplies... these rebels must be well-organized.",0);
		run_dialog(1);
		set_flag(6,18,1);
	}

break;


beginstate 25; //climbing higher

	if(get_flag(6,3) < 2) {
		reset_dialog();
		add_dialog_str(0,"As you climb higher up behind the falls, their roar begins to quiet down. The ground is also drier up here.",0);
		add_dialog_str(1,"There's something about all of this that bothers you. If the rebels had the time and organization to carve out this tunnel, then what else could they be doing?",0);
		run_dialog(1);
		set_flag(6,3,2);
	}

break;

beginstate 26; //even higher up

	if(get_flag(6,3) < 3) {
		reset_dialog();
		add_dialog_str(0,"Odd. You can hear the falls getting louder again, even though you could swear you're heading farther from them, into the cliffs.",0);
		add_dialog_str(1,"Though it's stranger that you feel a breeze coming from up ahead.",0);
		run_dialog(1);
		set_flag(6,3,3);
	}

break;

beginstate 27; //dead trees and rebel caches

	if(get_flag(6,3) < 4) {
		reset_dialog();
		add_dialog_str(0,"You continue to creep forward, listening for more rebels... and your patience is rewarded when you spot a guard standing next to some piles of supplies. Perhaps you can still surprise them.",0);
		add_dialog_str(1,"You also smell a fire, and something like vinegar.",0);
		run_dialog(1);
		set_flag(6,3,4);
	}

break;

beginstate 28; //the clearing

	if(get_flag(6,3) < 5) {
		reset_dialog();
		add_dialog_str(0,"The passage you were in abruptly opens into a clearing of sorts. Looking up, you can actually see the sky.",0);
		add_dialog_str(1,"It must have taken thousands of years for this little clearing to form. And looking north, you can see a fairly decent-sized waterfall. That's probably what carved this all out.",0);
		add_dialog_str(2,"You'd take more time to think about it, but you can smell smoke and hear low muttering. There must be more rebels nearby.",0);
		run_dialog(1);
		set_flag(6,3,5);
	}

break;

beginstate 29; //waterside

	if(get_flag(6,11) == 0) {
		reset_dialog();
		add_dialog_str(0,"The water in this stream is almost disturbingly clear, and incredibly cold. Looking to the east, you think you can see the stream fall away into the rock.",0);
		add_dialog_str(1,"This stream is quite a bit of water, actually. The current would sweep you away in an instant if you were to jump in.",0);
		add_dialog_str(2,"There's also a passage leading back into the rock off to the west.",0);
		run_dialog(1);
		set_flag(6,11,1);
	}

break;


beginstate 30; //empty boxes (specobj)

	if(get_flag(6,12) == 0) {
		message_dialog("You're a little leery about opening this box, given these rebels' tendency to use explosives. But it doesn't smell odd, and it looks like the rebels themselves didn't handle it with much care.","You tentatively ease the box open, and thankfully, nothing explodes.");
		set_flag(6,12,1);
		}

break;


beginstate 31; //sloping up dialog

	if(get_flag(6,3) < 6) {
		reset_dialog();
		add_dialog_str(0,"As the passage slopes up, the sound of the falls starts to pick up again. You also hear what sounds like wood being dragged across rocky ground.",0);
		add_dialog_str(1,"Maybe you can finally figure out what's going on here.",0);
		run_dialog(1);
		set_flag(6,3,6);
		}

break;


beginstate 33; //the campfire

	message_dialog("You lean in to search the fire, and you burn yourselves.","Well, that was stupid.");
	damage_near_loc(35,31,10,1,1);

break;

beginstate 34; //Joshua's fire

	message_dialog("You lean in to search the fire, and you burn yourselves.","Well, that was stupid.");
	damage_near_loc(8,16,10,1,1);

break;


beginstate 35; //Cutscene!!!

	if(get_flag(5,8) == 2)
		pctalker = get_flag(5,10);
	else
		pctalker = random_party_member(); 

	if(get_flag(6,13) == 0) {
		message_dialog("Now you can hear someone muttering to themselves.","Deciding that now is probably the best time to act, you cautiously draw weapons and approach.");
		play_sound(18);
		set_character_pose(1000,2);
		force_instant_terrain_redraw();
		pause(5);
		force_view_center(15,17);
		march_party(15,17);
		play_sound(49);
		force_instant_terrain_redraw();
		pause(2);
		force_view_center(14,16);
		march_party(14,16);
		play_sound(50);
		force_instant_terrain_redraw();
		pause(2);
		force_view_center(13,16);
		march_party(13,16);
		play_sound(49);
		force_instant_terrain_redraw();
		pause(2);
		force_view_center(12,16);
		march_party(12,16);
		play_sound(50);
		force_instant_terrain_redraw();
		pause(2);
		force_view_center(11,16);
		march_party(11,16);
		play_sound(49);
		force_instant_terrain_redraw();
		pause(1);
		set_character_facing(1000,0);
		force_instant_terrain_redraw();

		pause(5);
		
		reset_dialog();
		add_dialog_str(0,"In the half-second that you take to glimpse this beautiful cavern, you see huge cascades of water pouring into this little lake. It flows off to the east and west, but you can't be sure where it leads.",0);
		add_dialog_str(1,"Come to think of it, you're not sure where you are anymore. But these aren't the main falls, you're sure of it.",0);
		add_dialog_str(2,"But now, the falls don't catch your eye. You're too busy staring at the lone rebel in the cavern.",0);
		if(get_flag(3,9) == 1)
			add_dialog_str(3,"And something about the air here reminds you of the Empire lab. You can't quite put your finger on it.",0);
		run_dialog(1);

		pause(5);
		force_view_center(12,15);
		force_instant_terrain_redraw();
		pause(3);
		force_view_center(12,14);
		force_instant_terrain_redraw();
		pause(3);
		force_view_center(12,13);
		force_instant_terrain_redraw();
		pause(3);
		if(get_flag(1,11) == 1) {
			text_bubble_on_char(19, "So, you've arrived...");
			force_instant_terrain_redraw();
			pause(16);
			erase_text_bubbles();
			text_bubble_on_char(19, "And just in time,");
			force_instant_terrain_redraw();
			pause(17);
			}
		else {
			text_bubble_on_char(19, "Welcome, friends.");
			force_instant_terrain_redraw();
			pause(16);
			erase_text_bubbles();
			text_bubble_on_char(19, "You may call me Joshua.");
			force_instant_terrain_redraw();
			pause(17);
			erase_text_bubbles();
			force_instant_terrain_redraw();
			pause(4);
			text_bubble_on_char(19, "You've arrived just in time...");
			force_instant_terrain_redraw();
			pause(17);
			}
		erase_text_bubbles();
		text_bubble_on_char(19, "Like the heroes always do.");
		force_instant_terrain_redraw();
		pause(18);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(8);
		text_bubble_on_char(19, "I suppose you'll want to know");
		force_instant_terrain_redraw();
		pause(16);
		erase_text_bubbles();
		text_bubble_on_char(19, "what I've been doing here.");
		force_instant_terrain_redraw();
		pause(16);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(2);

		if(get_flag(1,11) == 1) {
			reset_dialog();
			add_dialog_str(0,"Then you see it. It's Joshua, the strange man you saw on the Pearl Bridge.",0);
			if(get_flag(1,15) == 1)
				add_dialog_str(1,"While his cryptic message makes a bit more sense now, it's not as if his friends were that much trouble to dispose of.",0);
			if(get_flag(1,14) == 1)
				add_dialog_str(2,"But it does beg the question: how did he escape you so easily before?",0);
			run_dialog(1);
			}

		if(party_size() > 1)
			text_bubble_on_char(random_party_member(), "Yes. Tell us.");
		else
			text_bubble_on_char(pctalker, "Yes. Tell me.");
		force_instant_terrain_redraw();
		pause(15);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(4);

		set_character_facing(19,4);
		force_instant_terrain_redraw();
		pause(4);
		relocate_character(19,12,12);
		force_instant_terrain_redraw();
		pause(4);
		text_bubble_on_char(19,"Well...");
		force_instant_terrain_redraw();
		pause(10);

		erase_text_bubbles();
		force_instant_terrain_redraw();

		reset_dialog();
		add_dialog_str(0,"_As you've surely figured out by now, it was none other than myself and my late colleagues who leveled the town of Hektos. We had bigger ambitions, though._",0);
		add_dialog_str(1,"_You see, we are unlike those pitiful rebels who are content to strike once and melt away into the shadows. We will not go quietly into the Empire's night until we make it our own._",0);
		add_dialog_str(2,"He gestures up at the falls behind him. _You see these? Most of their flow is channeled back down into the earth. However, some of it feeds the main falls._",0);
		add_dialog_str(3,"_So we thought, if we burned Hektos to the ground, we might as well put out the fire. We'll flood the town, and the fort if we can._",0);
		add_dialog_str(4,"Another sweeping gesture, this time toward the crates that litter the ground. _And these? More explosives. To seal up this cavern and redirect the water._",0);
		add_dialog_str(5,"_They're already armed, and so are the others that we've planted. They're going to go off no matter what, my friends._",0);
		run_dialog(1);

		pause(2);

		message_dialog("He grins widely. _Oh, and I almost forgot to thank you for your help. That package you delivered was just what we needed to finish the detonators for this batch of explosives._","");

		pause(2);

		text_bubble_on_char(pctalker, "Enough.");
		force_instant_terrain_redraw();
		pause(10);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(4);
		text_bubble_on_char(pctalker, "You see, that won't happen");
		force_instant_terrain_redraw();
		pause(12);
		erase_text_bubbles();
		text_bubble_on_char(pctalker, "if I kill you first.");
		force_instant_terrain_redraw();
		pause(12);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(5);

		text_bubble_on_char(19, "You're angry at me? Wonderful!");
		force_instant_terrain_redraw();
		pause(10);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(3);
		set_character_pose(19,2);
		play_sound(18);
		text_bubble_on_char(19, "That will make killing you much easier!");
		force_instant_terrain_redraw();
		pause(15);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(10);
		text_bubble_on_char(19, "You see, you can't stop me.");
		force_instant_terrain_redraw();
		pause(15);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		text_bubble_on_char(19, "Once I get these crates into the water,");
		force_instant_terrain_redraw();
		pause(10);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(2);

		put_effect_on_char(19,8,10,1);
		run_animation_sound(4);
		erase_char(19);
		activate_hidden_group(1);
		force_instant_terrain_redraw();

		pause(5);
		set_character_pose(1000,0);
		force_instant_terrain_redraw();
		pause(3);
		text_bubble_on_char(pctalker, "?");
		force_instant_terrain_redraw();
		pause(10);
		erase_text_bubbles();
		force_instant_terrain_redraw();
		pause(2);

		reset_dialog();
		add_dialog_str(0,"At first, you think you've been yelling at an illusion. But then, you hear his voice...",0);
		add_dialog_str(1,"_Then I shall win. And now you will die, friends._",0);
		if(get_flag(1,14) == 1)
			add_dialog_str(2,"Well, at least that explains how Joshua got away from you before.",0);
		run_dialog(1);
		force_view_center(11,16);
		force_instant_terrain_redraw();

		block_entry(1);
		set_flag(6,13,1);
		}

break;


beginstate 36; //boxes of explosives (not Joshua's) - specobj

	message_dialog("These boxes smell very strange, and very similar to the lab at Fort Galima. And the package you delivered there, now that you think of it.","You have a bad feeling that these are explosives, so you don't even try to touch them.");

break;


beginstate 37;

	if(get_flag(6,19) == 1)
		end();
	reset_dialog();
	add_dialog_str(0,"You're a little leery about opening this box, given these rebels' tendency to use explosives. But it doesn't smell odd, and it looks like the rebels themselves didn't handle it with much care.",0);
	add_dialog_str(1,"You tentatively ease the box open, and thankfully, the piles of papers inside it don't explode.",0);
	add_dialog_str(2,"Plucking a sheet of aged paper off the top of the pile, you read:",0);
	add_dialog_str(3,"The plan is as discussed. The rebellion will never fail, but I trust you to continue without us. The rats are on our heels, and we must flee.",10);
	add_dialog_str(4,"The message is dated several years ago, and it leaves you wondering how long this group of rebels has been on its own.",0);
	run_dialog(1);
	set_flag(6,19,1);


break;


beginstate 40; //block the boat until the fight is over

	if(get_flag(6,15) != 1) {
	if(get_flag(6,14) != 1) {
		reset_dialog();
		add_dialog_str(0,"You see no good reason to get into the boat while Joshua is still alive. After all, he could just blow the cliffs to bits when you try to go past them.",0);
		run_dialog(1);
		block_entry(1);
		}
	else {
		reset_dialog();
		add_dialog_str(0,"You wisely climb into the boat, unwilling to risk being trapped by a cave-in. After all, some of these explosives could still go off, and they'd probably kill you.",0);
		add_dialog_str(1,"You can see two ways out of this. You can try to catch the westward flow, which will probably take you out onto the main falls.",0);
		add_dialog_str(2,"Of course, there's always the eastern flow, which goes... well, you're not sure where. But wherever it is, it's less likely to explode than where you are right now.",0);
		add_dialog_str(3,"Which way do you paddle?",0);
		add_dialog_choice(0,"West.");
		add_dialog_choice(1,"East.");
		add_dialog_choice(2,"Get out of the boat.");
		choice = run_dialog(1);

		if(choice == 1) {
			set_flag(6,15,1);
			force_view_center(12,10);
			relocate_character(0,16,29);
			relocate_character(1,17,29);
			relocate_character(2,18,29);
			relocate_character(3,19,29);
			set_total_visibility(1);
			force_instant_terrain_redraw();

			pause(5);
			play_sound(-85);
			set_terrain(12,10,0);
			set_terrain(11,10,451);
			force_view_center(11,10);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(11,10,0);
			set_terrain(10,10,451);
			force_view_center(10,10);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(10,10,0);
			set_terrain(9,10,451);
			force_view_center(9,10);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(9,10,0);
			set_terrain(8,10,451);
			force_view_center(8,10);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(8,10,0);
			set_terrain(7,10,451);
			force_view_center(7,10);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(7,10,0);
			set_terrain(6,10,451);
			force_view_center(6,10);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(6,10,0);
			set_terrain(6,11,450);
			force_view_center(6,11);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(6,11,0);
			set_terrain(5,11,451);
			force_view_center(5,11);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(5,11,0);
			set_terrain(5,12,450);
			force_view_center(5,12);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(5,12,0);
			set_terrain(4,12,451);
			force_view_center(4,12);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(4,12,0);
			set_terrain(4,13,450);
			force_view_center(4,13);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(4,13,0);
			set_terrain(3,13,451);
			force_view_center(3,13);
			force_instant_terrain_redraw();						pause(5);
			play_sound(85);

			set_total_visibility(0);
			force_instant_terrain_redraw();

			reset_dialog();
			add_dialog_str(0,"The current picks up quickly, and you feel the boat being dragged out of the cavern. You can see sunlight through the mist ahead, and a cool breeze rushes up to greet you.",0);
			add_dialog_str(1,"Then, your boat bounces off a large submerged rock, and you are catapulted into the current. Before you go under, you catch a glimpse of blue sky through the mist.",0);
			add_dialog_str(2,"After that, you are plunged into darkness, and all you can hear is the sound of the falls.",0);
			}
		else if(choice == 2){
			set_flag(6,15,1);
			set_total_visibility(1);
			force_instant_terrain_redraw();

			force_view_center(12,10);
			relocate_character(0,16,29);
			relocate_character(1,17,29);
			relocate_character(2,18,29);
			relocate_character(3,19,29);
			set_total_visibility(1);
			force_instant_terrain_redraw();

			pause(5);
			play_sound(-85);
			set_terrain(12,10,0);
			set_terrain(13,10,505);
			force_view_center(13,10);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(13,10,0);
			set_terrain(14,10,505);
			force_view_center(14,10);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(14,10,0);
			set_terrain(15,10,505);
			force_view_center(15,10);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(15,10,0);
			set_terrain(15,9,504);
			force_view_center(15,9);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(15,9,0);
			set_terrain(16,9,505);
			force_view_center(16,9);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(16,9,0);
			set_terrain(17,9,505);
			force_view_center(17,9);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(17,9,0);
			set_terrain(18,9,505);
			force_view_center(18,9);
			force_instant_terrain_redraw();						pause(5);
			play_sound(-85);
			set_terrain(18,9,0);
			set_terrain(19,9,505);
			force_view_center(19,9);
			force_instant_terrain_redraw();						pause(5);
			play_sound(85);

			set_total_visibility(0);
			force_instant_terrain_redraw();

			reset_dialog();
			add_dialog_str(0,"The current picks up quickly, and you feel the boat being dragged out of the cavern. The tunnel ahead of you is pitch-black.",0);
			add_dialog_str(1,"Your boat rockets down the tunnel, gets whipped around a corner, and is thrown over a small waterfall. For a second, you can glimpse the clearing you passed through earlier.",0);
			add_dialog_str(2,"Before you can brace yourself, the boat falls away beneath you, and you realize that you're falling down a rather long waterfall.",0);
			add_dialog_str(3,"The boat hits the water shortly before you do, and you promptly lose consciousness.",0);
			}
		else {
			block_entry(1);
			end();
			}
		run_dialog(1);

		force_view_center(49,7);
		force_instant_terrain_redraw();
		play_sound(-100);
		pause(4);
		play_sound(100);

		move_to_new_town(8,5,14);

		}
		}

break;


beginstate 50; //try to leave

	if(get_flag(6,13) == 1) {
		reset_dialog();
		add_dialog_str(0,"As you begin to head back down towards the clearing, you reconsider the situation.",0);
		if(get_flag(6,14) == 0)
			add_dialog_str(1,"Joshua is still alive, and still working to load explosives into the current. He'll finish, one way or another.",0);
		else
			add_dialog_str(2,"The explosives are still there, and even though they won't be enough to flood the valley, they can still explode and trap you in the cave. So perhaps this isn't the best way to leave.",0);
		add_dialog_str(3,"Do you want to try to leave this way?",0);
		add_dialog_choice(0,"Yes.");
		add_dialog_choice(1,"No.");

		choice = run_dialog(1);
		
		if(choice == 2)
			block_entry(1);
		else {
			play_sound(-108);
			pause(2);
			play_sound(-108);
			pause(2);
			play_sound(-108);
			pause(2);
			play_sound(-108);
			pause(2);
			play_sound(-108);
			pause(2);
			play_sound(-108);
			pause(2);
			reset_dialog();
			add_dialog_str(0,"You don't make it very far until you hear a loud rumble, accompanied shortly after by the sound of huge sharp rocks crushing you to death.",0);
			if(get_flag(6,14) == 0)
				add_dialog_str(1,"Looks like Joshua beat you in the end...",0);
			else
				add_dialog_str(1,"The explosives might not have been enough to flood the valley, but they were definitely powerful enough to take care of you.",0);
			run_dialog(1);

			kill_char(1000,2,0);
		}
	}

break;